#include "string_util.h"
using namespace std;

// Returning vector is not efficient, however, it's clear.
vector<string> string_split(const string& args, const string& sep) {
    vector<string> result;
    unsigned int id = 0, prev = 0;
    while (true) {
        id = args.find_first_of(sep, id);
        if (id == string::npos) {
            result.push_back(args.substr(prev));
            break;
        } else {
            result.push_back(args.substr(prev, id - prev));
            id++;
            prev = id;
        }
    }
    return result;
}

void string_replace(string& strBig, const string& strsrc,
        const string& strdst) {
    string::size_type pos = 0;
    string::size_type srclen = strsrc.size();
    string::size_type dstlen = strdst.size();
    while( (pos = strBig.find(strsrc, pos)) != string::npos){
        strBig.replace(pos, srclen, strdst);
        pos += dstlen;
    }
}
